CentOS 7
Sponsored Link

Redis : Basic Usage#5
2016/07/21
 
This is the Basic Usage of Redis with "redis-cli" client program.
Following examples are basic one, you can see more commands on Official Site below.
⇒ http://redis.io/commands
[1] This is the basic Usage of Sets.
[root@dlp ~]#
redis-cli -a password
# add member to a Set (possible to multiple members with space)
127.0.0.1:6379> sadd set01 member01 
(integer) 1

# get number of members of a Set
127.0.0.1:6379> scard set01 
(integer) 1

# remove specified member of a Set
127.0.0.1:6379> srem set01 member03 
(integer) 1

# determine if specified member exists or not
127.0.0.1:6379> sismember set01 member01 
(integer) 1

# get all members of a Set
127.0.0.1:6379> smembers set01 
1) "member03"
2) "member02"
3) "member01"
127.0.0.1:6379> smembers set02 
1) "member02"
2) "member05"
3) "member04"
127.0.0.1:6379> smembers set03 
1) "member06"
2) "member02"
3) "member01"

# get members of the set resulting from the intersection of all the given sets
127.0.0.1:6379> sinter set01 set02 set03 
1) "member02"

# equal to SINTER above, but instead of showing the result, it is stored to destination Set(first argument)
127.0.0.1:6379> sinterstore set04 set01 set02 set03 
(integer) 1
127.0.0.1:6379> smembers set04 
1) "member02"

# get members of the set resulting from the difference between the first set and all the successive sets
127.0.0.1:6379> sdiff set01 set02 set03 
1) "member03"

# equal to SDIFF above, but instead of showing the result, it is stored to destination Set(first argument)
127.0.0.1:6379> sdiffstore set05 set01 set02 set03 
(integer) 1

127.0.0.1:6379> smembers set05 
1) "member03"

# get members of the set resulting from the union of all the given sets
127.0.0.1:6379> sunion set01 set02 set03 
(integer) 1

# equal to SUNION above, but instead of showing the result, it is stored to destination Set(first argument)
127.0.0.1:6379> sunionstore set06 set01 set02 set03 
(integer) 6
127.0.0.1:6379> smembers set06 
1) "member06"
2) "member03"
3) "member04"
4) "member02"
5) "member01"
6) "member05"

# move member from a Set(first arg) to a Set(2nd arg)
127.0.0.1:6379> smove set01 set02 member03 
(integer) 1
 
Tweet